from agent_comparator2 import AgentComparator2
from agents import Agent1 as my_agent
from agents import Agent3 as plus_agent
from text_example import createRealDatasets
from matplotlib import pyplot as plt

def tester(sizes):
    
    results = {}
    datasets = createRealDatasets()
    
    for name, data in datasets.items():
        
        result = {'mine':{},'plus':{},'mc':{}}
        
        for size in sizes:
            
            my_agent.set(size)
            plus_agent.set(size)
            
            class mine(my_agent):
                pass
            class theirs(plus_agent):
                pass
            
            (result['mine'][size], result['plus'][size],result['mc'][size]) = AgentComparator2().run(data, mine, theirs, 1, 30, 10)
        results[name] = result
    return results

sizes = range(1,26)

results = tester(sizes)




for name,test in results.items():

    xs = sizes
    mine = map(lambda x : test['mine'][x], sizes)
    their = map(lambda x : test['plus'][x], sizes)
    mc = map(lambda x : test['mc'][x], sizes)
    f = plt.figure()
    
    f.suptitle(name)
    #ax = f.add_subplot(111)
    ax = f.add_axes([0.1, 0.1, 0.8, 0.7])

    ax.set_xlabel('#features')
    ax.set_ylabel('accuracy')
    l1, = ax.plot(xs, mine, 'b--o', ms=10, lw=2, mfc='blue', label = 'my_agent')
    l2, = ax.plot(xs, their, 'g--o', ms=10, lw=2, mfc='green', label = 'defualt_agent')
    l3, = ax.plot(xs, mc, 'r--o', ms=10, lw=2, mfc='red', label = 'mc significance')
    
    f.legend((l1, l2, l3),('my_agent','plus','mc significance'),'upper left')
    
    f.savefig('./compare_agent_with_plus_agent/'+name)
    